/* eslint  no-param-reassign: "off" */
import { Config } from './lib/types';
import log from './lib/log';
import { setConfig } from './lib/config';
import callbackList from './lib/report';
import { addClickListener } from './core/click-listener';
import { addViewListener } from './core/view-listener';
import { addPageViewListener } from './core/page-listener';

// 初始化fish配置，开启fish所有监听
export function init(options?: Config) {
  const config = setConfig(Object.assign(callbackList, options));
  if (typeof window !== 'object') return;
  config.debug && log.info('Initialization configuration: ', config);
  // click
  addClickListener(config);
  // view
  addViewListener(config);
  // pageView
  addPageViewListener(config);
  config.debug && log.info('Complete event subscription');
}

export default init;
